package edu.sysu.demo.petrabbit;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

class ExpirationMessagePostProcessor implements MessagePostProcessor {

  private final long expireMillis; // 毫秒

  static ExpirationMessagePostProcessor create(long ttl) {
    return new ExpirationMessagePostProcessor(ttl);
  }

  private ExpirationMessagePostProcessor(long expireMillis) {
    this.expireMillis = expireMillis;
  }

  @Override
  public Message postProcessMessage(Message message) {
    // 设置per-message的失效时间
    message.getMessageProperties().setExpiration(String.valueOf(expireMillis));
    return message;
  }
}
